version: '3.8'

services:
  web:
    build: ./src
    command: |
      bash -c 'while !</dev/tcp/db/5432; do sleep 1; done; gunicorn app:app --bind=0.0.0.0:8000 --timeout 15'
    # Use for app debugging:
#    command: |
#      bash -c 'while !</dev/tcp/db/5432; do sleep 1; done; python app.py'
    volumes:
      - ./src/:/usr/src/app/
    ports:
      - "8000:8000"
    environment:
      - DATABASE_URL=postgresql://admin:admin@db/skillbox_db
  db:
    image: postgres:15.1-alpine
    command: ["postgres", "-c", "config_file=/etc/postgresql.conf"]
    volumes:
      # Postgres data folder must be totally empty on first start.
      # Therefore, we use `postgres.conf` from another location.
      - postgres_data:/var/lib/postgresql/data/
      - ./postgres/postgresql.conf:/etc/postgresql.conf
    expose:
      - 5432
    environment:
      - POSTGRES_USER=admin
      - POSTGRES_PASSWORD=admin
      - POSTGRES_DB=skillbox_db
  pgadmin:
      image: dpage/pgadmin4
      container_name: pgadmin4
      ports:
          - "80:80"
      environment:
          PGADMIN_DEFAULT_EMAIL: hazadus7@gmail.com
          PGADMIN_DEFAULT_PASSWORD: password
      volumes:
          - ./postgres/pgadmin:/var/lib/pgadmin

volumes:
  postgres_data: